package com.factory.factorymethod.order;


import com.factory.factorymethod.pizzapojo.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author 薛虎
 * @date 2020/12/17 11:14
 * 简单工厂模式
 */
public abstract class OrderPizza {


    //构造器
    public OrderPizza() {
        Pizza pizza = null;
        String orderType; //订购披萨的类型

        do {
            orderType = getType();
            pizza = createPizza(orderType); //抽象方法,由工厂子类完成

            //输出pizza 制作的过程
            //1.准备原材料
            pizza.prepare();
            //2.烘烤
            pizza.bake();
            //3.切割
            pizza.cut();
            //4.打包
            pizza.box();
        } while (true);

    }

    //定义一个抽象方法,createPizza,让各个工厂子类自己实现
    public abstract Pizza createPizza(String orderType);

    //写一个方法,可以获取客户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类:");
            String str = bufferedReader.readLine();
            return str;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

}
